package com.wangzhen.spring.inject;

import com.wangzhen.spring.inject.holder.UserHolder;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;

/**
 * XML方式演示set注入（手动注入）
 * 在xml文件中显示的指定UserHolder对象要依赖的userbean对象
 * <bean id="userHolder" class="com.wangzhen.spring.inject.holder.UserHolder">
 *         <property name="user" ref="superUser"/>
 * </bean>
 */
public class XmlSetterInjectDemo {

    public static void main(String[] args) {
        DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory();

        XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(beanFactory);
        // 加载XML配置
        String xmlLoaction = "classpath:/META-INF/dependcy-setter-context.xml";
        reader.loadBeanDefinitions(xmlLoaction);

        UserHolder bean = beanFactory.getBean(UserHolder.class);
        System.out.println(bean);

    }
}
